package com.istock.user.controller.vue;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.istock.base.common.api.model.ApiBaseResponse;
import com.istock.base.common.api.model.RetStatusEnum;
import com.istock.union.user.client.SSOClientUtils;
import com.istock.union.user.model.Constants;
import com.istock.union.user.model.RoleInfo;
import com.istock.union.user.model.RoleInfoModel;
import com.istock.union.user.model.SSOUser;
import com.istock.union.user.service.RoleInfoService;

@Controller
@RequestMapping("/s/roleInfo")
public class VueRoleInfoController {

	@Autowired
	private RoleInfoService roleInfoService;
	/**
	 * 根据用户ID和机构查询角色：标记已有角色
	 * 
	 * @param userId
	 * @param deptId
	 * @return
	 */
	@RequestMapping("/getUserRolesByUserIdVue")
	@ResponseBody
	public ApiBaseResponse<List<RoleInfo>> getUserRolesByUserIdVue(String userId) {
		List<RoleInfo> roleList = roleInfoService.selectUserRolesByUserId(userId);
		return new ApiBaseResponse<List<RoleInfo>>(RetStatusEnum.SUCCESS,Constants.API_RESPONSE_SUCCESS_CODE, 
				Constants.API_RESPONSE_SUCCESS_MESSAGE, roleList);
	}
	
	/**
	 * 根据用户ID和机构查询角色：标记已有角色
	 * 
	 * @param userId
	 * @param deptId
	 * @return
	 */
	@RequestMapping("/getRolesByUserIdVue")
	@ResponseBody
	public ApiBaseResponse<List<RoleInfoModel>> getRolesByUserIdVue() {
		SSOUser user = SSOClientUtils.getInstance().findCurrentUser();
		List<RoleInfoModel> roleList = roleInfoService.selectRolesByUserId(user.getUserId());
		return new ApiBaseResponse<List<RoleInfoModel>>(RetStatusEnum.SUCCESS,Constants.API_RESPONSE_SUCCESS_CODE, 
				Constants.API_RESPONSE_SUCCESS_MESSAGE, roleList);
	}
}
